/* GB2312 Encoding */
/*-----------------------------------------------------------------------
|                            FILE DESCRIPTION                           |
-----------------------------------------------------------------------*/
/*----------------------------------------------------------------------
  - File name     : log.h
  - Author        : liuzhihua (liuzhihuawy@163.com)
  - Update date   : 2023.04.27
  -	Brief         : log level control
  - Version       : v1.0
-----------------------------------------------------------------------*/
/*-----------------------------------------------------------------------
|                               UPDATE NOTE                             |
-----------------------------------------------------------------------*/
/**
  * Update note:
  * ------------   ---------------   ----------------------------------
  *     Date            Author                      Note
  * ------------   ---------------   ----------------------------------
  *   2023.04.27      liuzhihua                  Create file          
***/

#ifndef _Log_H_
#define _Log_H_

#ifdef  __cplusplus
    extern "C" {
#endif
/*-----------------------------------------------------------------------
|                                NCLUDES                                |
-----------------------------------------------------------------------*/
#include <stdint.h>
#include "task_main.h"
/*-----------------------------------------------------------------------
|                                DEFINES                                |
-----------------------------------------------------------------------*/
#define LOG_FORMAT_SIZE 128
/*1. 设置打印级别 */
enum LOG_LEVEL{
        LOG_LEVEL_NONE,
        LOG_LEVEL_DEBUG,
        LOG_LEVEL_INFO,
        LOG_LEVEL_WARN,
        LOG_LEVEL_ERROR,
        LOG_LEVEL_FATAL,
};

/* 2. log 打印 重写 */
void log_fun(int level, const char *opt, const char* tag, int line, const char *func, const char *fmt, ...);

/* 3. 各打印级别宏 */
/*
 *@LOG_NONE
 */ 
#define LOGN(data, len) \
  UARTx_Printn(&huart3, (uint8_t*)data, len)
#define LOGS(str) \
  UARTx_Print(&huart3, str, strlen(str))
#define LOG_FAST(fmt, ...) \
  UARTx_Printf(&huart3, fmt, ##__VA_ARGS__)
/*
 *@LOG_DBG
 */ 
#define LOG_DBG(tag, fmt, ...) \
  log_fun(LOG_LEVEL_DEBUG, "D", tag , __LINE__, __func__, fmt, ##__VA_ARGS__)

/*
 *@LOG_INFO
 */ 
#define LOG_INFO(tag, fmt, ...)  \
  log_fun(LOG_LEVEL_INFO, "I", tag , __LINE__, __func__, fmt, ##__VA_ARGS__)

/*
 *@LOG_WARN
 */ 
#define LOG_WARN(tag, fmt, ...)  \
  log_fun(LOG_LEVEL_WARN, "W", tag , __LINE__, __func__, fmt, ##__VA_ARGS__)

/*
 *@LOG_ERR
 */ 
#define LOG_ERR(tag, fmt, ...)  \
  log_fun(LOG_LEVEL_ERROR, "E", tag , __LINE__, __func__, fmt, ##__VA_ARGS__)

/*
 *@LOG_FATAL
 */ 
#define LOG_FATAL(tag, fmt, ...)  \
  log_fun(LOG_LEVEL_FATAL, "F", tag , __LINE__, __func__, fmt, ##__VA_ARGS__)

void log_set_level(int level);
#define LogSetLevel(lv) do{LOG_FAST("Log level set: " #lv "\n");log_set_level(lv);}while(0)
/*-----------------------------------------------------------------------
|                                  API                                  |
-----------------------------------------------------------------------*/

#ifdef __cplusplus
	}
#endif
#endif
